import React from 'react'
import { BrowserRouter as Router, Redirect, Route, NavLink, Switch } from 'react-router-dom';
import './my.css'
import book from './image/book.png'
import Bookdetail from './Bookdetail.js'

class Mybook extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
			res: [],
			userid: localStorage.getItem("userid")
  	    };
    }
	//查所有随笔
	componentDidMount() {
		fetch('http://62.234.30.197:8088/topics/idcha', {
			method: 'post',
			body: JSON.stringify({'userid':`${this.state.userid}`}),
			headers: {
			    "Access-Control-Allow-Origin":"*",
			    'content-type': 'application/json'
			},
			mode: 'cors'
		})
		.then(res=>res.json())
		.then(res=> {
			//console.log(res)
			this.setState({
				res: res
			});
		})
	}
    render() {
		let list = this.state.res;
		return (
        <div>
			<div className='Mymsgsetnamesig-top'>
				<span className='my-return' onClick={() => this.props.history.goBack()}>&lt;</span>
				<span className='my-setnamesig-top'>我推荐的书籍</span>
			</div>
        
			<div><ul>{
				this.state.res.map((item, idx) => {
				var str = `${item.bookname}`;
				//console.log(str);
					if(str != 'null' && str != '') {
						return <li className='book-show2' key={idx}>
							<img src={book} className='leftbook floatleft'/>
							<div className='' id=''>
								<br /><span style={{fontSize:'20px'}}>{item.bookname}</span><br /><br />
								<span>作者:{item.name}</span><br />
								<span>分类:{item.type}</span>
								<div><a href="#" style={{color:'#73C1F3', float:'right'}}>&gt;&gt;点此查看详情</a></div><br />
							</div>
						</li>
					}
				})
			}</ul></div>
			<div style={{height:'300px'}}></div>
        	<div id="container"></div>
        </div>
    );
  }
}
export default Mybook
//<button onClick={this.topicschaall}>查这个userid的所有随笔</button><br /><br />